package cz.cvut.fit.mi.dpo.mvc.view;

import javax.swing.*;
import java.awt.*;

/**
 * @author David Pertl
 * @author Martin Štekl <steklmar@fit.cvut.cz>
 */
public class Window extends JFrame implements IMessageWriter {

	public Window(AView view) {
		super();

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setTitle("MI-DPO - MVC/MVP");

		setDefaultLookAndFeelDecorated(true);

		Container content = getContentPane();
		content.setBackground(Color.lightGray);
		content.add(view);

		setVisible(true);
		pack();
		setSize(700, 300);
		center();
	}

	@Override
	public void showMessage(String message) {
		JOptionPane.showMessageDialog(null, message, "Error!", JOptionPane.ERROR_MESSAGE);
	}

	private void center() {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension windowSize = getSize();
		int windowX = Math.max(0, (screenSize.width - windowSize.width) / 2);
		int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2);
		setLocation(windowX, windowY);
	}

}
